package com.wjs.juc.Atmoic;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

class MyNumber{
    public AtomicInteger number=new AtomicInteger();
    public void addPlus(){
        number.getAndIncrement();
    }
}
public class AtmoicIntegerDemo {
    public static int size =50;
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(size);
        MyNumber myNumber = new MyNumber();
        for (int i = 0; i < 50; i++) {
            new Thread(()->{
                try {
                    for (int i1 = 0; i1 < 1000; i1++) {
                        myNumber.addPlus();
                    }
                } finally {
                    countDownLatch.countDown();
                }
            }).start();
        }
        countDownLatch.await();
        System.out.println("结果为"+myNumber.number);
    }
}
